#ifndef CONTEXT_CAR_H
#define CONTEXT_CAR_H

#include <list>
#include <string>

#include "Engine/Synaptic/Misc.h"
#include "Engine/Reason.h"
#include "Engine/Sense.h"
#include "Engine/Visual.h"
#include "Engine/Resource/Graphic.h"
#include "Engine/Kinetic/Movement.h"
#include "Engine/Kinetic/Animation.h"

namespace Context { class Driver; } 
namespace Context { class Track; } 

namespace Context {

/* Drivable car. It should have a driver that implements AI or interaction */
class Car : public Engine::Reason, public Engine::Sense, public Engine::Visual {
	public:
		Car(std::string carName, Context::Track * track, Context::Driver * driver); 
		virtual ~Car();
		
		virtual void pulse(int delta);
		virtual void exit() { };
		virtual Engine::Resource::GraphicList display();
		
		inline virtual void throttle() { throttling = true; }; /* Throttle the engine */
		inline virtual void reverse() { reversing = true; }; /* Reverse acceleration */
		inline virtual void turnRight(double angle = 2.0f);
		inline virtual void turnLeft(double angle = 2.0f);
		
		
		Misc::Vector2d position;
	private:
		static std::list<Car *> runningCars;
		
		Engine::Kinetic::Movement movement;
		
		std::string name;
		Context::Track * track; // track that this car is running
		Context::Driver * driver; // driver controlling this car
		Engine::Resource::Graphic carGfx;
		
	protected:
		bool throttling;
		bool reversing;
		double orientation;
};

void Car::turnLeft(double angle) { 
	orientation += angle;
	movement.setVelocity(movement.readVelocity().rotate(-angle));

}

void Car::turnRight(double angle) { 
	orientation -= angle;
	movement.setVelocity(movement.readVelocity().rotate(angle));
}

} // namespace Context
#endif
